package com.pocket.mic.dao;

import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

/**
 * Created with IntelliJ IDEA.
 * User: v.wupingteng
 * Date: 12-8-15
 * Time: 下午3:43
 * To change this template use File | Settings | File Templates.
 */
public abstract class BaseDao extends SqlMapClientDaoSupport {
    /** Logger available to subclasses */
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     *
     *
     * @param id
     * @param paramObject
     * @return
     * @throws Exception
     */
    protected Object getObject(String id, Object paramObject) throws Exception{

        Object result = null;
        try {
            result = getSqlMapClientTemplate().queryForObject(id, paramObject);
        } catch (Exception e) {
            logger.error(e.getStackTrace().toString());
            throw e;
        }

        return result;
    }

    /**
     *
     *
     * @param id
     * @param paramObject
     * @return
     * @throws Exception
     */
    protected List<?> getObjects(String id, Object paramObject) throws Exception{

        List<?> result = null;
        try {
            result = getSqlMapClientTemplate().queryForList(id, paramObject);
        } catch (Exception e) {
            logger.error(e.getStackTrace().toString());
            throw e;
        }

        return result;
    }

    protected void updateObject(String id, Object paramObject) throws Exception{
        getSqlMapClientTemplate().update(id, paramObject);
    }

}
